package com.ruoyi.system.mc.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Objects;

/*
 *  @author 雨安
 *  类名： McUserAddress
 *  创建时间：2024/5/27
 */
@Data//getter + setter + toString
@AllArgsConstructor//有参
@NoArgsConstructor//无参
@TableName(value = "mc_user_address")
public class McUserAddress extends BaseEntity implements Serializable {
        /**
         * 用户收货地址ID
         */
        @TableId(type = IdType.AUTO)
        private Long addressId;

        /**
         * 用户ID
         */
        private Long userId;

        /**
         * 收货地址
         */
        private String address;

        /**
         * 收货手机号
         */
        private String phoneNumber;

        //获取条件构造器
        public LambdaQueryWrapper<McUserAddress> getLambdaQueryWrapper(McUserAddress mcUserAddress){
                //返回条件构造器
                return new LambdaQueryWrapper<McUserAddress>()
                        //通过用户ID查询因为用户只能看到用户自己的地址信息
                        .eq(McUserAddress::getUserId, SecurityUtils.getUserId())
                        //判断通过收获地址进行查询
                        .like(StringUtils.isNotBlank(mcUserAddress.getAddress()),McUserAddress::getAddress,mcUserAddress.getAddress())
                        //判断收获手机号
                        .like(StringUtils.isNotBlank(mcUserAddress.getPhoneNumber()),McUserAddress::getPhoneNumber,mcUserAddress.getPhoneNumber())
                         //判断通过逻辑删除进行查找
                        .eq(McUserAddress::getDeleteFlag,Boolean.FALSE);
        }
}
